import * as dateFormat from './format.date.js';
import * as numberFormat from './format.number.js';

const formatter = { ...dateFormat, ...numberFormat }

const formatObj = {
    d1: 'YYYY-MM-DD',
    d2: 'YYYY/MM/DD',
    d3: 'YYYY年MM月DD日',
    d4: 'YYYY-MM-DD hh:mm:ss',
    d5: 'YYYY-MM-DD hh:mm:ss',
    n1: 'formatNumber1',
    n2: 'formatNumber2',
    n3: 'formatNumber3',
    n4: 'formatNumber4',
    n5: 'formatNumber5',
    n6: 'formatNumber6',
    n7: 'formatNumber7'
}

function tableFormatterValue(row, column, cellValue) {
    if (!cellValue) {
        return ''
    }
    const { dateFormatter } = dateFormat
    // 兼容导出代码
    if(typeof column === 'string' && !!column) {
        if (column.charAt(0) === 'd') {
            return dateFormatter(cellValue, formatObj[column])
        }
        return formatter[formatObj[column]](cellValue)
    }
    if(typeof column === 'object' && !!column.formatS && !!column.show) {
        if (column.formatS.charAt(0) === 'd') {
            return dateFormatter(cellValue, formatObj[column.formatS])
        }
        return formatter[formatObj[column.formatS]](cellValue)
    }
    return cellValue;
}


export default { tableFormatterValue }



